{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import json\n",
    "def main(arg1: str) -> dict:\n",
    "    try:\n",
    "        # 解析JSON字符串并自动处理Unicode转义\n",
    "        data = json.loads(arg1)\n",
    "        \n",
    "        # 带格式优化的内容提取\n",
    "        if 'content' in data:\n",
    "            # 执行三阶格式处理：\n",
    "            # 1. 去除首尾空白 2.合并连续空行 3.保留自然段落\n",
    "            formatted_content = data['content'].strip().replace('\\n\\n', '\\n')\n",
    "            return {\n",
    "                \"result\":formatted_content\n",
    "                } \n",
    "        return {\n",
    "                \"result\":\"[ERROR] 文档缺少content字段\"\n",
    "                } \n",
    "    \n",
    "    except json.JSONDecodeError as e:\n",
    "        return {\n",
    "                \"result\":f\"[CRITICAL] JSON格式异常: {str(e)}\"\n",
    "                } \n",
    "    except TypeError:\n",
    "        return {\n",
    "                \"result\":\"[WARNING] 输入必须为有效字符串\"\n",
    "                } \n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
